get contents by user
Fetch user-specific content from TabNews API by specifying username, page, per_page, and strategy to organize posts efficiently.
Instructions
get contents by user from tabnews api
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | The page number to get | |
| per_page | No | The number of contents per page | |
| strategy | No | The strategy to get the contents | |
| username | Yes | The username to get the contents |
Implementation Reference
- src/tools/status.ts:96-120 (handler)MCP tool handler for 'get contents by user' that invokes the service function and formats the response as MCP text contenthandler: async (params: GetContentByUserParams): Promise<McpResponse> => { try { const result = await getContentsByUser({ username: params.username, page: params.page, per_page: params.per_page, strategy: params.strategy, }); const content: McpTextContent = { type: "text", text: `Contents:\n\n${JSON.stringify(result, null, 2)}`, }; return { content: [content], }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get contents by user: ${error.message}`); } else { throw new Error("Failed to get contents by user"); } } },
- src/tools/status.ts:87-95 (schema)Zod input schema defining parameters for the tool: username (required string), optional page, per_page (numbers), strategy (enum) used for MCP tool validationparameters: { username: z.string().describe("The username to get the contents"), page: z.number().optional().describe("The page number to get"), per_page: z.number().optional().describe("The number of contents per page"), strategy: z .enum(["relevant", "new", "old"]) .optional() .describe("The strategy to get the contents"), },
- src/index.ts:38-43 (registration)Registration of the 'get contents by user' tool with the MCP server using server.tool()server.tool( getContentsByUserTool.name, getContentsByUserTool.description, getContentsByUserTool.parameters, getContentsByUserTool.handler );
- src/services/api.ts:39-57 (helper)Helper service function that performs the actual API fetch to TabNews for contents by user, builds query params and returns the dataexport async function getContentsByUser({ username, page = 1, per_page = 30, strategy = "relevant", }: GetContentByUserParams): Promise<TabNewsContent[]> { const queryParams = new URLSearchParams({ page: page.toString(), per_page: per_page.toString(), strategy: strategy, }); const response = await fetch( `${TABNEWS_API_URL}/contents/${username}?${queryParams}` ); const data = await response.json(); return data as TabNewsContent[]; }